package com.sgb.merchant.view.activity;

import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;

import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.link.entity.AMapAddressEntity;
import com.sgb.link.entity.EventConstant;
import com.sgb.link.entity.MainEvent;
import com.sgb.link.entity.merchant.IndustryCategoryEntity;
import com.sgb.link.entity.merchant.IndustryType;
import com.sgb.link.entity.merchant.InvestmentDetailEntity;
import com.sgb.link.entity.merchant.InvestmentEntity;
import com.sgb.link.service.MapService;
import com.sgb.link.router.PathMerchant;
import com.sgb.link.router.PathUser;
import com.sgb.link.utils.EntityConversion;
import com.sgb.merchant.R;
import com.sgb.merchant.databinding.MerchantActivityProjectPublishBinding;
import com.sgb.merchant.view.adapter.PicImageAdapter;
import com.sgb.merchant.viewmodel.PublishProjectModel;
import com.sgb.merchant.widget.TypeFilterPopWindow;
import com.swgk.core.base.model.entity.RouterKey;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.DisplayUtil;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PickerHelper;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author:王彬臣
 * @date: 2021/8/15
 * @Description: 发布投资项目简介
 */
@Route(path = PathMerchant.InvestmentPublishActivity)
public class InvestmentPublishActivity extends BaseActivity<PublishProjectModel, MerchantActivityProjectPublishBinding> implements ItemInputTextView.OnWholeItemClickListener {
    @Autowired(name = RouterKey.DATA, desc = "详情data")
    InvestmentDetailEntity mEntity;
    @Autowired(name = RouterKey.BOOLEAN, desc = "是否编辑")
    boolean isEdit;
    @Autowired(name = PathUser.AMapDialog)
    MapService mapService;

    @Autowired(name = RouterKey.BOOLEAN2,desc="是否来着我的页面")
    boolean isSelf=false;

    PicImageAdapter imageAdapter;
    //图片上传
    private List<LocalMedia> selectList = new ArrayList<>();
    private List<String> urls = new ArrayList<>();
    private List<File> fileList = new ArrayList<>();
    String title, type, money, name, phone, time, endTime,
            address, intro, stage, size, state, revenue, revenueDesc, land, lanDesc;
    boolean hasContent;//是否有填写类型
    //时间选择器
    private TimePickerView mTimePicker;
    //是否是开始时间
    private boolean mIsBegin;
    //类型选择器
    private OptionsPickerView mStatusPicker, mStagePicker, mSizePicker, mRevenuePicker, mLandPicker;
    InvestmentEntity investmentEntity;
    List<List<IndustryCategoryEntity>> subChildren = new ArrayList<>();
    List<IndustryCategoryEntity> categoryEntityList = new ArrayList<>();
    List<IndustryCategoryEntity> mStatusData = new ArrayList<>();
    List<IndustryCategoryEntity> mStageData = new ArrayList<>();
    List<IndustryCategoryEntity> mSizeData = new ArrayList<>();
    List<IndustryCategoryEntity> mRevenueData = new ArrayList<>();
    List<IndustryCategoryEntity> mLandData = new ArrayList<>();

    private long startTime, endTimes;
    TypeFilterPopWindow mTypePop;
    IndustryType industryType = new IndustryType();
    int selectPickerType;
    Map<String, Object> mMap = new HashMap<>();

    @Override
    protected int layoutId() {
        return R.layout.merchant_activity_project_publish;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(PublishProjectModel.class);
    }

    @Override
    protected void init() {
        ARouter.getInstance().inject(this);
        investmentEntity = new InvestmentEntity();
        mBinding.includeTitle.titleView.setText("招商项目");
        mBinding.tvNext.setOnClickListener(this);
        mBinding.itvType.setOnWholeItemClickListener(this);
        mBinding.itvTime.setOnWholeItemClickListener(this);
        mBinding.itvEndTime.setOnWholeItemClickListener(this);
        mBinding.itvStatus.setOnWholeItemClickListener(this);
        mBinding.itvRevenue.setOnWholeItemClickListener(this);
        mBinding.itvRevenue.setContentTextEnd();
        mBinding.itvLand.setOnWholeItemClickListener(this);
        mBinding.itvLand.setContentTextEnd();
        mBinding.itvSize.setOnWholeItemClickListener(this);
        mBinding.itvSize.setContentTextEnd();
        mBinding.itvStage.setOnWholeItemClickListener(this);
        mBinding.itvStage.setContentTextEnd();
        mBinding.rlAddress.setOnClickListener(this);
        mBinding.itvPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
        mBinding.includeTitle.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getEditContent();
                if (hasContent) {//有填写类提示用户
                    showHintDialog();
                    return;
                }
                finish();
            }
        });

        imageAdapter = new PicImageAdapter(this, null, null, 10);
        imageAdapter.setDelClickListener(new PicImageAdapter.delClickListener() {
            @Override
            public void del(int position) {
                ArrayList<String> allUrls= imageAdapter.getUrls();
                if (isEdit &&investmentEntity.getImages()!=null&& investmentEntity.getImages().size() != 0) {
                    if (allUrls.get(position).contains("http")||allUrls.get(position).contains("https")) {
                        investmentEntity.getImages().remove(position);
                    }
                }
            }
        });
        mBinding.recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        mBinding.recyclerView.setAdapter(imageAdapter);
        mTypePop = new TypeFilterPopWindow(this);
        mTypePop.setHeight(DisplayUtil.getScreenHeight(this) * 2 / 3);
        mTypePop.setBgView(mBinding.popLayout);
        if (mEntity != null) {
            investmentEntity = EntityConversion.modelA2B(mEntity, InvestmentEntity.class);
        }
        mViewModel.setInfo(mEntity,imageAdapter,mBinding);
        initEvent();
        initPicker();
    }



    private void getPotionsData() {
        DialogHelper.showProgressDialog(this, "加载中").setCanceledOnTouchOutside(true);
        mViewModel.getOptions();
    }

    private void initEvent() {
        mBinding.edtMoney.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                //如果第一个数字为0，第二个不为点，就不允许输入
                if (s.toString().startsWith("0") && s.toString().trim().length() > 1) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        mBinding.edtMoney.setText(s.subSequence(0, 1));
                        mBinding.edtMoney.setSelection(1);
                        return;
                    }
                }
                //如果第一为点，直接显示0.
                if (s.toString().startsWith(".")) {
                    mBinding.edtMoney.setText("0.");
                    mBinding.edtMoney.setSelection(2);
                    return;
                }
                //限制输入小数位数(2位)
                if (s.toString().contains(".")) {
                    if (s.length() - 1 - s.toString().indexOf(".") > 2) {
                        s = s.toString().subSequence(0, s.toString().indexOf(".") + 2 + 1);
                        mBinding.edtMoney.setText(s);
                        mBinding.edtMoney.setSelection(s.length());
                    }
                } else if (!s.toString().contains(".") && s.length() > 10) {//限制输入10位整数
                    s = s.toString().subSequence(0, 10);
                    mBinding.edtMoney.setText(s);
                    mBinding.edtMoney.setSelection(s.length());
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        mBinding.etInfo.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mBinding.tvCount.setText(s.length() + "/5000");

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        mTypePop.setOnResultCallBack(new BasePopWindow.OnResultCallBack() {
            @Override
            public void result(Object result) {
                mBinding.itvSize.setContent("");
                investmentEntity.setCapacityScaleNo(0l);
                industryType = (IndustryType) result;
                mBinding.itvType.setContent("行业分类已选择");
                mBinding.llTypeContent.setVisibility(View.VISIBLE);
                mBinding.itvType.setDeliverLineVG(false);
                StringBuffer strType = new StringBuffer();
                if (!TextUtils.isEmpty(industryType.getIndustryCategoryFirstName())) {
                    strType.append(industryType.getIndustryCategoryFirstName());
                    investmentEntity.setIndustryCategoryFirstNo(industryType.getIndustryCategoryFirstNo());
                    mMap.clear();
                    mMap.put("industryClassificationOne",industryType.getIndustryCategoryFirstNo());
                }
                if (!TextUtils.isEmpty(industryType.getIndustryCategorySecondName())) {
                    strType.append("/");
                    strType.append(industryType.getIndustryCategorySecondName());
                    investmentEntity.setIndustryCategorySecondNo(industryType.getIndustryCategorySecondNo());
                    mMap.clear();
                    mMap.put("industryClassificationTwo",industryType.getIndustryCategorySecondNo());
                } else {
                    investmentEntity.setIndustryCategorySecondNo(0l);
                }
                if (!TextUtils.isEmpty(industryType.getIndustryCategoryThreeName())) {
                    strType.append("/");
                    strType.append(industryType.getIndustryCategoryThreeName());
                    investmentEntity.setIndustryCategoryThreeNo(industryType.getIndustryCategoryThreeNo());
                    mMap.clear();
                    mMap.put("industryClassificationThree",industryType.getIndustryCategoryThreeNo());
                } else {
                    investmentEntity.setIndustryCategoryThreeNo(0l);
                }
                if (!TextUtils.isEmpty(industryType.getIndustryCategoryFourName())) {
                    strType.append(industryType.getIndustryCategoryFourName());
                    investmentEntity.setIndustryCategoryFirstNo(industryType.getIndustryCategoryFourNo());
                    mMap.clear();
                    mMap.put("industryClassificationFour",industryType.getIndustryCategoryFourNo());
                } else {
                    investmentEntity.setIndustryCategoryFourNo(0l);
                }
                mBinding.tvContent.setText(strType.toString());


            }
        });
        mViewModel.liveDataCategoryList.observe(this, data -> {
            categoryEntityList.addAll(data);
            mTypePop.setDataList(categoryEntityList);
            mTypePop.showPopwindowBottom(mBinding.rlRoot);
        });

        mViewModel.ldOptions.observe(this, data -> {
            if (data.getStageOptions() != null) {
                mStageData.addAll(data.getStageOptions());
            }
            if (data.getCapacityScaleOptions() != null) {
                mSizeData.addAll(data.getCapacityScaleOptions());
            }
            if (data.getLandDiscountOptions() != null) {
                mLandData.addAll(data.getLandDiscountOptions());
            }
            if (data.getTaxDiscountOptions() != null) {
                mRevenueData.addAll(data.getTaxDiscountOptions());
            }
            switch (selectPickerType){
                case 0:
                    if (mStageData.size() > 0) {
                        mStagePicker.show();
                    }
                    break;

                case 2:
                    if (mRevenueData.size() > 0) {
                        mRevenuePicker.show();
                    }
                    break;
                case 3:
                    if (mLandData.size() > 0) {
                        mLandPicker.show();
                    }
                    break;
            }
        });
        mViewModel.ldCapacityScaleOptions.observe(this, data -> {

            if (data.getCapacityScaleOptions() != null&&data.getCapacityScaleOptions().size()>0) {
                mSizeData.addAll(data.getCapacityScaleOptions());
                mSizePicker.show();
            }else{
                MToast.showToast(this,"无类型选择");
            }

        });
    }

    //温馨提示
    private void showHintDialog() {
        new RoundDialog.Builder(InvestmentPublishActivity.this)
                .title("温馨提示")
                .content("此操作将丢失当前表单填写内容，\n" + "是否继续？")
                .cancel("取消")
                .confirm("确定")
                .cancelable(false)
                .confirmCallback(v12 -> finish()).show();
    }

    //获取填写内容
    public void getEditContent() {
        title = mBinding.itvName.getContent();
        type = mBinding.itvType.getContent();
        money = mBinding.edtMoney.getText().toString();
        name = mBinding.itvPerson.getContent();
        phone = mBinding.itvPhone.getContent();
        stage = mBinding.itvStage.getContent();
        size = mBinding.itvSize.getContent();
        state = mBinding.itvStatus.getContent();
        revenue = mBinding.itvRevenue.getContent();
        revenueDesc = mBinding.etRevenue.getEditContent();
        land = mBinding.itvLand.getContent();
        lanDesc = mBinding.etLand.getEditContent();
       /* time = mBinding.itvTime.getContent();
        endTime = mBinding.itvEndTime.getContent();*/
        address = mBinding.itvAddress.getText().toString();
        intro = mBinding.etInfo.getText().toString();
        if (!TextUtils.isEmpty(title) || !TextUtils.isEmpty(type) ||
                !TextUtils.isEmpty(money) || !TextUtils.isEmpty(name) || !TextUtils.isEmpty(phone) ||
                !TextUtils.isEmpty(address) || !TextUtils.isEmpty(stage) || !TextUtils.isEmpty(size) ||
                !TextUtils.isEmpty(state) || !TextUtils.isEmpty(revenue) || !TextUtils.isEmpty(revenueDesc) ||
                !TextUtils.isEmpty(land) || !TextUtils.isEmpty(lanDesc) ||
                !TextUtils.isEmpty(intro) || imageAdapter.getUrls().size() > 0) {
            hasContent = true;
        } else {
            hasContent = false;
        }

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_next) {
            getEditContent();
            if (TextUtils.isEmpty(title)) {
                MToast.showToast(this, "请输入项目名称！");
                return;
            }
            if (TextUtils.isEmpty(type)) {
                MToast.showToast(this, "请选择行业分类！");
                return;
            }
            if (TextUtils.isEmpty(money)) {
                MToast.showToast(this, "请输入项目总金额！");
                return;
            }
            if (TextUtils.isEmpty(stage)) {
                MToast.showToast(this, "请选择立项阶段！");
                return;
            }
            if (TextUtils.isEmpty(size)) {
                MToast.showToast(this, "请选择产能规模！");
                return;
            }
           /* if (TextUtils.isEmpty(state)) {
                MToast.showToast(this, "请选择上下架状态");
                return;
            }*/
            if (TextUtils.isEmpty(name)) {
                MToast.showToast(this, "请输入联系人！");
                return;
            }
        /*    if (TextUtils.isEmpty(phone)) {
                MToast.showToast(this, "请输入联系电话！");
                return;
            } else */if (!TextUtils.isEmpty(phone)&&!CheckUtils.isMobileForService(phone)) {
                MToast.showToast(this, "请输入正确的电话格式！");
                return;
            }
            if (!TextUtils.isEmpty(revenueDesc) && TextUtils.isEmpty(revenue)) {
                MToast.showToast(this, "请选择税收优惠");
                return;
            }
            if (!TextUtils.isEmpty(lanDesc) && TextUtils.isEmpty(land)) {
                MToast.showToast(this, "请选择土地优惠");
                return;
            }
            if (TextUtils.isEmpty(address)) {
                MToast.showToast(this, "请点击图标定位项目地址！");
                return;
            }
            if (TextUtils.isEmpty(intro)) {
                MToast.showToast(this, "请输入项目简介！");
                return;
            }
            if (!isEdit) {
                investmentEntity.setItemNo("");
            }
            investmentEntity.setItemName(title);
            investmentEntity.setItemMoney(money);
            investmentEntity.setLinkName(name);
            investmentEntity.setLinkPhone(TextUtils.isEmpty(phone)?"":phone);
            investmentEntity.setItemInfo(intro);
            investmentEntity.setLandDiscountContent(lanDesc);
            investmentEntity.setTaxDiscountContent(revenueDesc);

            ARouter.getInstance().build(PathMerchant.ProjectCommitActivity).withSerializable(RouterKey.DATA, investmentEntity).
                    withStringArrayList(RouterKey.DATA1, imageAdapter.getUrls())
                    .withBoolean(RouterKey.BOOLEAN,isSelf)
                    .navigation(this, 1000);
        } else if (v.getId() == R.id.rl_address) {
            if (mapService != null)
                mapService.launchMap(this);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            getEditContent();
            if (hasContent) {
                showHintDialog();
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {// 图片结果回调
                // 图片、视频、音频选择结果回调
                selectList = PictureSelector.obtainMultipleResult(data);
                fileList.clear();
                urls.clear();
                for (LocalMedia localMedia : selectList) {
                    File file = new File(localMedia.getCompressPath());
                    fileList.add(file);
                    urls.add(localMedia.getCompressPath());
                }
                imageAdapter.setDatas(selectList, urls);
                imageAdapter.setFileList(fileList);
            } else if (requestCode == 2500) {
                AMapAddressEntity entity = mViewModel.get(data);
                if (entity == null) return;
                mBinding.itvAddress.setText(entity.getProvince() + entity.getCity() + entity.getDistrict() + entity.getSnippet());
                investmentEntity.setAddressInfo(entity.getSnippet());
                investmentEntity.setLat(entity.getLatitude() + "");
                investmentEntity.setLng(entity.getLongitude() + "");
                investmentEntity.setProviceId(Integer.valueOf(entity.getProvinceNo()));
                investmentEntity.setCityId(Integer.valueOf(entity.getCityNo()));
                investmentEntity.setRegionId(Integer.valueOf(entity.getDistrictNo()));
            } else if (requestCode == 1000) {
                if(data.getSerializableExtra("info")==null){
                    finish();
                }
                InvestmentEntity entity = (InvestmentEntity) data.getSerializableExtra("info");
                investmentEntity.setSeniorityInfo(entity.getSeniorityInfo());
                investmentEntity.setCollaboratorQualifications(entity.getCollaboratorQualifications());
                investmentEntity.setOtherRequirement(entity.getOtherRequirement());
            }
        }
        if (requestCode == 255) {
            if (data == null) {
                return;
            }
        }
    }



    @Override
    public void OnWholeItemClick(View v) {
        if (v.getId() == R.id.itv_type) {
            if (mViewModel.liveDataCategoryList.getValue() == null) {
                mViewModel.getindustryCategoryList();
            } else {
                mTypePop.showPopwindowBottom(mBinding.rlRoot);
            }
        } else if (v.getId() == R.id.itv_time) {
            mIsBegin = true;
            mTimePicker.setTitleText("请选择报名时间");
            mTimePicker.show();
        } else if (v.getId() == R.id.itv_end_time) {
            mIsBegin = false;
            mTimePicker.setTitleText("请选择截止时间");
            mTimePicker.show();
        } else if (v.getId() == R.id.itv_status) {
            mStatusPicker.show();
        } else if (v.getId() == R.id.itv_land) {
            selectPickerType=3;
            if (mLandData.size() > 0) {
                mLandPicker.show();
            } else {
                getPotionsData();
            }


        } else if (v.getId() == R.id.itv_revenue) {
            selectPickerType=2;
            if (mRevenueData.size() > 0) {
                mRevenuePicker.show();
            } else {
                getPotionsData();
            }

        } else if (v.getId() == R.id.itv_stage) {
            selectPickerType=0;
            if (mStageData.size() > 0) {
                mStagePicker.show();
            } else {
                getPotionsData();
            }

        } else if (v.getId() == R.id.itv_size) {
            mSizeData.clear();
            DialogHelper.showProgressDialog(this, "加载中").setCanceledOnTouchOutside(true);
            mViewModel.getCapacityScale(mMap);
        }
    }

    private void initPicker() {
        IndustryCategoryEntity data1 = new IndustryCategoryEntity();
        data1.setCategoryName("上架中");
        data1.setCategoryNo("0");
        IndustryCategoryEntity data2 = new IndustryCategoryEntity();
        data2.setCategoryName("已下架");
        data2.setCategoryNo("1");
        mStatusData.add(data1);
        mStatusData.add(data2);
        mStatusPicker = PickerHelper.with(this).getCommonPicker("选择上下架状态", mStatusData, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                IndustryCategoryEntity firstCategory = mStatusData.get(options1);
                mBinding.itvStatus.setContent(firstCategory.getCategoryName());
                investmentEntity.setStatus(firstCategory.getCategoryNo());
            }
        });
        mStagePicker = PickerHelper.with(this).getCommonPicker("选择立项阶段", mStageData, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                IndustryCategoryEntity firstCategory = mStageData.get(options1);
                mBinding.itvStage.setContent(firstCategory.getCategoryName());
                investmentEntity.setStageNo(Long.valueOf(firstCategory.getCategoryNo()));
            }
        });
        mSizePicker = PickerHelper.with(this).getCommonPicker("选择产能规模", mSizeData, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                IndustryCategoryEntity firstCategory = mSizeData.get(options1);
                mBinding.itvSize.setContent(firstCategory.getCategoryName());
                investmentEntity.setCapacityScaleNo(Long.valueOf(firstCategory.getCategoryNo()));
            }
        });
        mRevenuePicker = PickerHelper.with(this).getCommonPicker("选择税收优惠", mRevenueData, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                IndustryCategoryEntity firstCategory = mRevenueData.get(options1);
                mBinding.itvRevenue.setContent(firstCategory.getCategoryName());
                investmentEntity.setTaxDiscountNo(Long.valueOf(firstCategory.getCategoryNo()));
            }
        });
        mLandPicker = PickerHelper.with(this).getCommonPicker("选择土地优惠", mLandData, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                IndustryCategoryEntity firstCategory = mLandData.get(options1);
                mBinding.itvLand.setContent(firstCategory.getCategoryName());
                investmentEntity.setLandDiscountNo(Long.valueOf(firstCategory.getCategoryNo()));
            }
        });
    }


    /**
     * 检查设置开始时间
     */
    private void checkBeginTime(Date date) {
        startTime = date.getTime();
        if (startTime < System.currentTimeMillis()) {
            MToast.showToast(getApplication(), "报名时间不能小于当前时间");
            return;
        }
        investmentEntity.setApplyStartTime(startTime);
        mBinding.itvTime.setContent(DateUtils.stampToDay6(String.valueOf(startTime)));
    }

    /**
     * 检查设置结束时间
     */
    private void checkEndTime(Date date) {
        endTimes = date.getTime();
        if (endTimes < System.currentTimeMillis()) {
            MToast.showToast(getApplication(), "截止时间不能小于当前时间");
            return;
        }
        investmentEntity.setApplyEndTime(endTimes);
        mBinding.itvEndTime.setContent(DateUtils.stampToDay6(String.valueOf(endTimes)));
    }
    @Override
    public boolean isUseEventBus() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(MainEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_MERCHANT_FINISH_PUBLIC) {
            finish();
        }
    }
}
